<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /*
            1 2 3 4 5
            */
            var removeNthFromEnd = function (head, n) {
                let dummy = new ListNode(0, head)
                let fast = dummy
                let slow = dummy
                while (n--) {
                    fast = fast.next
                }
                if (!fast) return slow.next
                while (fast && fast.next) {
                    fast = fast.next
                    slow = slow.next
                }
                slow.next = slow.next.next
                return dummy.next
            }
        </script>
    </body>
</html>
